package com.ruoyi.tcsp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.tcsp.domain.mysql.TcspNewsScien;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tcsp.service.ITcspNewsScienService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科技新闻Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/tcsp/scienNews")
public class TcspNewsScienController extends BaseController
{
    @Autowired
    private ITcspNewsScienService tcspNewsScienService;

    /**
     * 查询科技新闻列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:list')")
    @GetMapping("/list")
    public TableDataInfo list(TcspNewsScien tcspNewsScien)
    {
        startPage();
        List<TcspNewsScien> list = tcspNewsScienService.selectTcspNewsScienList(tcspNewsScien);
        return getDataTable(list);
    }

    /**
     * 导出科技新闻列表
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:export')")
    @Log(title = "科技新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcspNewsScien tcspNewsScien)
    {
        List<TcspNewsScien> list = tcspNewsScienService.selectTcspNewsScienList(tcspNewsScien);
        ExcelUtil<TcspNewsScien> util = new ExcelUtil<TcspNewsScien>(TcspNewsScien.class);
        util.exportExcel(response, list, "科技新闻数据");
    }

    /**
     * 获取科技新闻详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcspNewsScienService.selectTcspNewsScienById(id));
    }

    /**
     * 新增科技新闻
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:add')")
    @Log(title = "科技新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcspNewsScien tcspNewsScien)
    {
        return toAjax(tcspNewsScienService.insertTcspNewsScien(tcspNewsScien));
    }

    /**
     * 修改科技新闻
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:edit')")
    @Log(title = "科技新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcspNewsScien tcspNewsScien)
    {
        return toAjax(tcspNewsScienService.updateTcspNewsScien(tcspNewsScien));
    }

    /**
     * 删除科技新闻
     */
    @PreAuthorize("@ss.hasPermi('tcsp:scienNews:remove')")
    @Log(title = "科技新闻", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcspNewsScienService.deleteTcspNewsScienByIds(ids));
    }
}
